package com.sptpc.demo.student;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/student")
public class StudentController {
    @PostMapping("/")
    public Student.StudentBuilder addNewStudent(@RequestBody Student student) {
        log.info("新增学生信息:{}", student);
        return Student.builder()
                .id(7L).adminssionDate(LocalDate.parse("2020-5-20"))
                .name("cq")
                .major("数字媒体");
    }

    @DeleteMapping("/")
    public String deleteStudent(@PathVariable Integer name) {
        log.info("要删除的学生信息:{}", name);
        return "删除成功";
    }
    @GetMapping("/")
    public List<Student> getAll(){
        List<Student> results=new ArrayList<>();
        results.add(Student.builder().name("cq")
                .adminssionDate(LocalDate.ofEpochDay(2020-05-25))
                .major("移动开发")
                .build());
        return results;
    }
    @PutMapping("/")
    public Student modifyStudent(Student request){
        log.info("修改的学生信息:{}",request);
        Student addStudent=Student.builder()
                .name("cq")
                .adminssionDate(LocalDate.ofEpochDay(2020-05-25))
                .major("数字媒体")
                .build();
        return addStudent;
    }
}
